//
//  BHBaseViewController.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/1.
//

import UIKit

@objc class BHBaseViewController: UIViewController {

    var page: Int = 1
    var canPopBack: Bool = true
    
    deinit {
        print("viewController is deinit \(self)")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        BHToast.cancelAllToast()
        SVProgressHUD.dismiss()
    }
    
    lazy var bh_navigationBar: BHCommonNavigationBar = {
        let view = BHCommonNavigationBar.loadFromXib()
        view.frame = CGRect(x: 0, y: 0, width: UIScreen.width, height: UIScreen.begainY)
        return view
    }()

    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = .white
        self.navigationController?.isNavigationBarHidden = true
        self.modalPresentationStyle = .fullScreen
        self.view.addSubview(self.bh_navigationBar)
        
        self.bh_navigationBar.title_label.text = self.title;
        
        self.bh_navigationBar.backBtn.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        self.bh_navigationBar.rightBtn.addTarget(self, action: #selector(rightBtnAction), for: .touchUpInside)
        self.bh_navigationBar.more_btn.addTarget(self, action: #selector(moreBtnAction), for: .touchUpInside)

    }
    
    override func viewDidLayoutSubviews() {
        self.view.bringSubviewToFront(self.bh_navigationBar)
    }
    
    
    @objc open func backAction() {
        self.navigationController?.popViewController(animated: true)
    }
    @objc open func rightBtnAction() {

    }
    
    @objc open func moreBtnAction() {

    }
}

extension BHBaseViewController {
    override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
        viewControllerToPresent.modalPresentationStyle = .fullScreen
        super.present(viewControllerToPresent, animated:flag, completion: completion)
    }
}
